home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / libpq / fe-pqstubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-02  |  4.5 KB  |  241 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    fe-pqstubs.c
  4.  *    
  5.  *   DESCRIPTION
  6.  *    These are frontend versions of various error handling and
  7.  *    memory mgt routines used in libpq.  
  8.  *
  9.  *   INTERFACE ROUTINES
  10.  *    palloc, pfree, ExceptionalCondition, ExcRaise
  11.  *    elog, AssertionFailed, form
  12.  *    
  13.  *   NOTES
  14.  *    These routines are NOT compiled into the postgres backend,
  15.  *    rather they end up in libpq.a.
  16.  *
  17.  *   IDENTIFICATION
  18.  *    $Header: /private/postgres/src/lib/libpq/RCS/fe-pqstubs.c,v 1.4 1991/11/13 08:55:31 clarsen Exp $
  19.  * ----------------------------------------------------------------
  20.  */
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25. #include <varargs.h>
  26.  
  27. #include "tmp/c.h"
  28. #undef palloc
  29. #undef pfree
  30. #include "utils/exc.h"
  31.  
  32. RcsId("$Header: /private/postgres/src/lib/libpq/RCS/fe-pqstubs.c,v 1.4 1991/11/13 08:55:31 clarsen Exp $");
  33.  
  34. #ifdef    _SBFSIZ
  35. typedef unsigned char iochar;
  36. #else
  37. typedef char iochar;
  38. #endif
  39.  
  40. #ifndef _IOSTRG
  41. #define _IOSTRG    0
  42. #endif
  43.  
  44. #ifndef    _NFILE
  45. #define _NFILE (-1)
  46. #endif
  47.  
  48. #define FormMaxSize    1024
  49. #define FormMinSize    (FormMaxSize / 8)
  50.  
  51. static    char    FormBuf[FormMaxSize];
  52. static    char    *FormBufP = FormBuf;
  53.  
  54. Exception FailedAssertion;
  55.  
  56. /* ----------------
  57.  *    palloc (frontend version)
  58.  *    pfree (frontend version)
  59.  * ----------------
  60.  */
  61. Pointer
  62. palloc(size)
  63.     Size size;
  64. {
  65.     return
  66.     malloc(size);
  67. }
  68.  
  69. void
  70. pfree(pointer)
  71.     Pointer    pointer;
  72. {
  73.     free(pointer);
  74. }
  75.  
  76. Pointer
  77. palloc_debug(file, line, size)
  78.     String file;
  79.     int       line;
  80.     Size   size;
  81. {
  82.     return
  83.     malloc(size);
  84. }
  85.  
  86. void
  87. pfree_debug(file, line, pointer)
  88.     String  file;
  89.     int        line;
  90.     Pointer pointer;
  91. {
  92.     free(pointer);
  93. }
  94.  
  95. /* ----------------
  96.  *    ExceptionalCondition (frontend version)
  97.  * ----------------
  98.  */
  99. void
  100. ExceptionalCondition(conditionName, exceptionP, detail, fileName, lineNumber)
  101.     const String    conditionName;
  102.     const Exception *exceptionP;
  103.     const String    detail;
  104.     const String    fileName;
  105.     const int       lineNumber;
  106. {
  107.     /*
  108.      * for picky compiler purposes
  109.      */
  110.     conditionName = conditionName;
  111.     exceptionP = exceptionP;
  112.     detail = detail;
  113.     fileName = fileName;
  114.     lineNumber = lineNumber;
  115.  
  116.     fprintf(stderr, "ExceptionalCondition called!\n");
  117.     exit(1);
  118. }
  119.  
  120. /* ----------------
  121.  *    ExcRaise (frontend version)
  122.  * ----------------
  123.  */
  124. void
  125. ExcRaise(arg1, string,ignore,ignore2)
  126.      Exception *arg1;
  127.      ExcDetail string;
  128.      ExcData ignore;
  129.      ExcMessage ignore2;
  130. {
  131.     fprintf(stderr, "Error: %s\n", (char *)string);
  132.     exit(1);
  133. }
  134.  
  135. /* ----------------
  136.  *    elog (frontend version)
  137.  * ----------------
  138.  */
  139. void
  140. elog()
  141. {
  142.     fprintf(stderr, "elog called!!\n");
  143.     exit(1);
  144. }
  145.  
  146. /* ----------------
  147.  *    AssertionFailed (frontend version)
  148.  * ----------------
  149.  */
  150. void
  151. AssertionFailed(assertionName, fileName, lineNumber)
  152.     const String    assertionName;
  153.     const String    fileName;
  154.     const int        lineNumber;
  155. {
  156.     if (!PointerIsValid(assertionName) || !PointerIsValid(fileName))
  157.     fprintf(stderr, "AssertionFailed: bad arguments\n");
  158.     else
  159.     fprintf(stderr,
  160.         "AssertionFailed(\"%s\", File: \"%s\", Line: %d)\n",
  161.         assertionName, fileName, lineNumber);
  162. #ifdef SABER
  163.     stop();
  164. #endif
  165.     exit(1);
  166. }
  167.  
  168. /* ----------------
  169.  *    form
  170.  * ----------------
  171.  */
  172. /*VARARGS1*/
  173. char *
  174. #ifdef lint
  175. form(fmt, va_alist)
  176.     char    *fmt;
  177. #else
  178. form(va_alist)
  179. #endif
  180.     va_dcl
  181. {
  182.     va_list    args;
  183.     char    *format;
  184.     char    *str;
  185.     FILE    fake;
  186.  
  187. /* Use vsprintf() with linux for this, so set sprite */
  188. #ifdef linux
  189. #undef sprite
  190. #define sprite 1
  191. #endif
  192. #if !sprite
  193.     /* ----------------
  194.      *    non-sprite hacks
  195.      * ----------------
  196.      */
  197. #ifdef    lint
  198.     fmt = fmt;
  199. #endif  /* lint */
  200.  
  201.     if (FormBufP + FormMinSize > FormBuf + FormMaxSize)
  202.     FormBufP = FormBuf;
  203.  
  204.     fake._cnt  = ((FormBuf + FormMaxSize) - FormBufP) - 1;
  205.     fake._base = fake._ptr = (iochar *)FormBufP;
  206.     fake._flag = _IOWRT | _IOSTRG;
  207.     fake._file = _NFILE;
  208. #endif /* sprite */
  209.     
  210.     va_start(args);
  211.     format = va_arg(args, char *);
  212.  
  213. #if !sprite
  214.     /* ----------------
  215.      *    when not in sprite use _doprnt.
  216.      * ----------------
  217.      */
  218.     _doprnt(format, args, &fake);
  219.     va_end(args);
  220.  
  221. #ifndef    lint
  222.     (void) putc('\0', &fake);
  223. #endif  /* lint */
  224.  
  225.     str = FormBufP;
  226.     FormBufP += strlen(FormBufP) + 1;
  227.     
  228. #else /* sprite */
  229.     /* ----------------
  230.      *    when in sprite, use vsprintf.
  231.      * ----------------
  232.      */
  233.     /* kai: Don't do this: str = vsprintf(FormBuf, format, args); */
  234.     str = FormBuf;
  235.     vsprintf(FormBuf, format, args);
  236.     va_end(args);
  237. #endif /* sprite */
  238.     
  239.     return (str);
  240. }
  241.